package com.woniu.postbar.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.common.entity.PageData;
import com.woniu.postbar.entity.dto.PostCollectDTO;
import com.woniu.postbar.entity.vo.PostCollectVO;
import com.woniu.postbar.mapper.PostCollectMapper;
import com.woniu.postbar.pojo.PostCollect;
import com.woniu.postbar.service.IPostCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wu
 * @since 2023-05-20
 */
@Service
public class PostCollectServiceImpl extends ServiceImpl<PostCollectMapper, PostCollect> implements IPostCollectService {


    @Autowired
    private PostCollectMapper postCollectMapper;

    @Override
    public Boolean increaseCollect(PostCollect collect) {
        return postCollectMapper.increaseCollect(collect);
    }

    @Override
    public Boolean deleteCollect(Integer id) {
        return postCollectMapper.deleteCollect(id);
    }

    @Override
    public PageData<List<PostCollectVO>> searchPage(Integer currentPage, Integer pageSize, PostCollectDTO collectDTO) {
        //创建分页对象
        IPage page = new Page(currentPage,pageSize);
        //调用mapper查询数据
        IPage<PostCollectVO> pageList = postCollectMapper.search(page,collectDTO);
        //封装成一个pageData的对象
        PageData pageData = new PageData();
        pageData.setTotal(pageList.getTotal());
        pageData.setData(pageList.getRecords());
        //返回数据
        return pageData;
    }
}
